/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package cn.newtest.bi.collection.service.impl;

import net.risesoft.risebi.collection.dao.SoInstanceDao;
import net.risesoft.risebi.collection.model.SoInstance;
import net.risesoft.risebi.collection.service.SoInstanceManager;
import net.risesoft.risebi.collection.service.UserSOManager;

import org.appfuse.dao.Dao;
import org.appfuse.service.impl.BaseManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * 
 * @author <a href="mailto: baiyibing@gmail.com">王锤</a>
 * @version $Revision$
 * 
 */
@Repository(value = "soInstanceManager")
@Transactional(rollbackFor = { java.lang.Exception.class })
public class SoInstanceManagerImpl extends BaseManager implements SoInstanceManager {
	private UserSOManager userSOManager;
	
	public UserSOManager getUserSOManager() {
		return userSOManager;
	}
	@Autowired
	public void setUserSOManager(UserSOManager userSOManager) {
		this.userSOManager = userSOManager;
	}

	private SoInstanceDao soInstanceDao;

	public SoInstanceDao getSoInstanceDao() {
		return soInstanceDao;
	}

	@Autowired
	public void setSoInstanceDao(SoInstanceDao soInstanceDao) {
		this.soInstanceDao = soInstanceDao;
	}

	public Dao getDao() {
		// TODO Auto-generated method stub
		return getSoInstanceDao();
	}

	public SoInstance getSoInstanceByAppGuidSoCode(String appGuid, String soCode)
			throws Exception {
		String hql = "from SoInstance as s where s.code = '" + soCode
				+ "' and s.application.guid='" + appGuid + "'";
		SoInstance soInstance = (SoInstance) this.getUniqueObject(hql);
		return soInstance;
	}

	public String removeSoInstance(SoInstance soi) throws Exception {
		//删除userso
		userSOManager.removeUserSoBySoI(soi.getGuid());
		this.removeObject(SoInstance.class, soi.getGuid());
		
		return "";
	}
}
